enable_testing()

if(NOT BUILD_SHARED_LIBS)
    find_package(Threads REQUIRED)
    set(CMAKE_CXX_FLAGS -pthread)
    if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
        set(CMAKE_EXE_LINKER_FLAGS "-static")
    endif()
endif()

add_executable(taint_reg taint_reg.cpp)
set_property(TARGET taint_reg PROPERTY CXX_STANDARD 17)
target_link_libraries(taint_reg triton)
add_test(TaintRegister taint_reg)
add_dependencies(check taint_reg)

add_executable(info_reg info_reg.cpp)
set_property(TARGET info_reg PROPERTY CXX_STANDARD 17)
target_link_libraries(info_reg triton)
add_test(InfoRegister info_reg)
add_dependencies(check info_reg)

add_executable(ir ir.cpp)
set_property(TARGET ir PROPERTY CXX_STANDARD 17)
target_link_libraries(ir triton)
add_test(IR ir)
add_dependencies(check ir)

add_executable(simplification simplification.cpp)
set_property(TARGET simplification PROPERTY CXX_STANDARD 17)
target_link_libraries(simplification triton)
add_test(Simplification simplification)
add_dependencies(check simplification)

add_executable(constraint constraint.cpp)
set_property(TARGET constraint PROPERTY CXX_STANDARD 17)
target_link_libraries(constraint triton)
add_test(Constraint constraint)
add_dependencies(check constraint)

add_executable(ctest_api ctest_api.cpp)
set_property(TARGET ctest_api PROPERTY CXX_STANDARD 17)
target_link_libraries(ctest_api triton)
add_test(TestAPI ctest_api)
add_dependencies(check ctest_api)

add_executable(block block.cpp)
set_property(TARGET block PROPERTY CXX_STANDARD 17)
target_link_libraries(block triton)
add_test(TestBlock block)
add_dependencies(check block)

find_package(LIEF QUIET)
find_package(fmt QUIET)
if(LIEF_FOUND AND fmt_FOUND)
    message(STATUS "LIEF found")
    message(STATUS "FMT found")
    add_executable(hooking_libc hooking_libc.cpp)
    set_property(TARGET hooking_libc PROPERTY CXX_STANDARD 17)
    target_link_libraries(hooking_libc triton LIEF::LIEF fmt::fmt)
    add_test(TestHookingLibc hooking_libc)
    add_dependencies(check hooking_libc)
endif()
